/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.FlightAdjustCompensation;
import com.sasis.dao.FlightAdjustCompensationDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class FlightAdjustCompensationDaoiBatis extends BaseDaoiBATIS implements FlightAdjustCompensationDao {

    /**
     * @see com.sasis.dao.FlightAdjustCompensationDao#getFlightAdjustCompensations(com.sasis.model.FlightAdjustCompensation)
     */
    public List getFlightAdjustCompensations(final FlightAdjustCompensation flightAdjustCompensation) {
          return getSqlMapClientTemplate().queryForList("getFlightAdjustCompensations", flightAdjustCompensation);
    }

    /**
     * @see com.sasis.dao.FlightAdjustCompensationDao#getFlightAdjustCompensation(Integer id)
     */
    public FlightAdjustCompensation getFlightAdjustCompensation(Integer id) {
        FlightAdjustCompensation flightAdjustCompensation = (FlightAdjustCompensation) getSqlMapClientTemplate().queryForObject("getFlightAdjustCompensation", id);

        //if (flightAdjustCompensation == null) {
            //throw new ObjectRetrievalFailureException(FlightAdjustCompensation.class, id);
        //}

        return flightAdjustCompensation;
    }

    /**
     * @see com.sasis.dao.FlightAdjustCompensationDao#saveFlightAdjustCompensation(FlightAdjustCompensation flightAdjustCompensation)
     */    
    public int saveFlightAdjustCompensation(final FlightAdjustCompensation flightAdjustCompensation) {
        Integer id = flightAdjustCompensation.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addFlightAdjustCompensation", flightAdjustCompensation);
        } else {
            getSqlMapClientTemplate().update("updateFlightAdjustCompensation", flightAdjustCompensation);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(FlightAdjustCompensation.class, id);
        }
        return id.intValue();
    }

    /**
     * @see com.sasis.dao.FlightAdjustCompensationDao#removeFlightAdjustCompensation(Integer id)
     */
    public void removeFlightAdjustCompensation(FlightAdjustCompensation flightAdjustCompensation) {
        getSqlMapClientTemplate().update("deleteFlightAdjustCompensation",  flightAdjustCompensation);
    }
}
